package com.yc.damai.damaiother.web;

import com.yc.damai.bean.Result;
import com.yc.damai.damaiother.mapper.ProductMapper;
import com.yc.damai.entity.DmProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/9/6
 * Email haijunzhou@hnit.edu.cn
 */
@RestController
public class ProductDo {
    @Autowired
    ProductMapper productMapper;

    @RequestMapping("queryHots")
    List<?> queryHots(){
        return productMapper.selectHots();
    }

    @RequestMapping("getPro")
    Result getPro(@RequestParam("cid") int cid, @RequestParam(defaultValue = "1") int pageIndex) {
        List<DmProduct> list = productMapper.selectPro(cid, (pageIndex - 1)*12);
        int total = productMapper.selectCount(cid);
        HashMap data = new HashMap<>();
        data.put("current", pageIndex);
        data.put("total", total);
        data.put("records", list);
        Result result = new Result(1, "成功", data);
        return result;
    }
}
